home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 112
/
EnigmaAmiga112CD.iso
/
dalla rivista
/
news
/
orbit
/
source
/
joystick_amiga.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-05-01
|
3KB
|
143 lines
/*
Amiga Joystick and Joypad support for ORBIT
29.04.2000 - written, tested, worked :)
30.04.2000 - added diagonal movement,
pitch roll for joypad,
fire while moving
*/
#include <libraries/lowlevel.h>
#include <clib/lowlevel_protos.h>
#include "orbit.h"
struct Library *LowLevelBase = NULL;
ULONG amiga_joy_type;
#define AMIGA_JOY_PORT 1
void InitJoy()
{
UBYTE i;
joy_available = 0;
if (LowLevelBase = (struct Library *)OpenLibrary("lowlevel.library", 40L))
{
/* we call this several times just to go sure */
for (i=0; i<3; i++)
{
amiga_joy_type = ReadJoyPort(AMIGA_JOY_PORT);
Delay(1);
}
if ((amiga_joy_type == JP_TYPE_GAMECTLR) || (amiga_joy_type == JP_TYPE_JOYSTK))
{
joy_available = 1;
return;
}
CloseLibrary(LowLevelBase);
LowLevelBase = NULL;
}
}
void JoyStick()
{
/* Ignore joystick motion if dead */
if ((state == STATE_DEAD1) || (state == STATE_DEAD2))
return;
switch(ReadJoyPort(AMIGA_JOY_PORT) - amiga_joy_type)
{
case JPF_BUTTON_RED:
PlayerFires();
break;
case JPF_JOY_UP:
player.move_up = 0.5;
break;
case JPF_JOY_DOWN:
player.move_down = 0.5;
break;
case JPF_JOY_LEFT:
player.move_left = 0.5;
break;
case JPF_JOY_RIGHT:
player.move_right = 0.5;
break;
case (JPF_JOY_UP + JPF_JOY_LEFT):
player.move_up =
player.move_left = 0.5;
break;
case (JPF_JOY_UP + JPF_JOY_RIGHT):
player.move_up =
player.move_right = 0.5;
break;
case (JPF_JOY_DOWN + JPF_JOY_LEFT):
player.move_down =
player.move_left = 0.5;
break;
case (JPF_JOY_DOWN + JPF_JOY_RIGHT):
player.move_down =
player.move_right = 0.5;
break;
case (JPF_BUTTON_FORWARD):
player.move_pitchright = 1.0;
break;
case (JPF_BUTTON_REVERSE):
player.move_pitchleft = 1.0;
break;
case (JPF_JOY_UP + JPF_BUTTON_RED):
player.move_up = 0.5;
PlayerFires();
break;
case (JPF_JOY_DOWN + JPF_BUTTON_RED):
player.move_down = 0.5;
PlayerFires();
break;
case (JPF_JOY_LEFT + JPF_BUTTON_RED):
player.move_left = 0.5;
PlayerFires();
break;
case (JPF_JOY_RIGHT + JPF_BUTTON_RED):
player.move_right = 0.5;
PlayerFires();
break;
case (JPF_JOY_UP + JPF_JOY_LEFT + JPF_BUTTON_RED):
player.move_up =
player.move_left = 0.5;
PlayerFires();
break;
case (JPF_JOY_UP + JPF_JOY_RIGHT + JPF_BUTTON_RED):
player.move_up =
player.move_right = 0.5;
PlayerFires();
break;
case (JPF_JOY_DOWN + JPF_JOY_LEFT + JPF_BUTTON_RED):
player.move_down =
player.move_left = 0.5;
PlayerFires();
break;
case (JPF_JOY_DOWN + JPF_JOY_RIGHT + JPF_BUTTON_RED):
player.move_down =
player.move_right = 0.5;
PlayerFires();
break;
case (JPF_BUTTON_FORWARD + JPF_BUTTON_RED):
player.move_pitchright = 1.0;
PlayerFires();
break;
case (JPF_BUTTON_REVERSE + JPF_BUTTON_RED):
player.move_pitchleft = 1.0;
PlayerFires();
break;
}
}
void FreeJoy()
{
if (LowLevelBase)
{
SetJoyPortAttrs(1, SJA_Reinitialize, TAG_DONE);
CloseLibrary(LowLevelBase);
}
}